package com.kaibes.core.base.store;

public class LimitStringStore {

    private int size = 0;
    private String[] values;
    
    public LimitStringStore(int size) {
        values = new String[size];
    }
    
    public boolean check(String value) {
        for (String string : values) {
            if (string.equals(value)) {
                return true;
            }
        }
        return false;
    }
    
    public boolean checkAndDelete(String value) {
        boolean flag = false;
        final int temp = size;
        for (int i = 0; i < temp; i++) {
            if (flag) {
                values[i-1] = values[i];
            } else if (values[i].equals(value)) {
                flag = true;
                size -= 1;
            }
        }
        return flag;
    }
    
    public void add(String value) {
        if (size == values.length) {
            for (int i = 1; i < size; i++) {
                values[i-1] = values[i];
            }
            size -= 1;
        }
        values[size] = value;
    }
    
    public void delete(String value) {
        boolean flag = false;
        final int temp = size;
        for (int i = 0; i < temp; i++) {
            if (flag) {
                values[i-1] = values[i];
            } else if (values[i].equals(value)) {
                flag = true;
                size -= 1;
            }
        }
    }
    
}
